<template>
  <div class="login">
    <div class="loginBox">
      <p class="title">用户登录</p>
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="0"
        class="demo-ruleForm"
      >
        <el-form-item label="" prop="user">
          <el-input v-model="ruleForm.user" prefix-icon="el-icon-user"></el-input>
        </el-form-item>
        <el-form-item label="" prop="password">
          <el-input type="password" v-model="ruleForm.password" prefix-icon="el-icon-unlock"></el-input>
        </el-form-item>
        <el-form-item label="" prop="captcha">
          <el-input class="captcha-input" type="text" v-model="ruleForm.captcha" prefix-icon="el-icon-key"></el-input>
          <el-button>获取验证码</el-button>
        </el-form-item>
      </el-form>
      <el-button class="loginBtn" type="primary" @click="submitForm('ruleForm')">登 录</el-button>
    </div>
  </div>
</template>
<script>
export default {
    data(){
        return {
            ruleForm:{
                user:'admin',//用户名
                password:'123456',//密码
                captcha:'123',//验证码
            },
            rules:{
                user: [
                    { required: true, message: '请输入用户名', trigger: 'blur' },
                    { min: 3, max: 6, message: '长度在 3 到 6 个字符', trigger: 'blur' }
                ],
                password:[
                    { required: true, message: '请输入密码', trigger: 'blur' },
                    { min: 1, max: 6, message: '长度在 1 到 6 个字符', trigger: 'blur' }
                ],
                captcha:[
                    {required:true,message:'请输入验证码',trigger:'blur'}
                ]
            }

        }
    },
    methods:{
        submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            // alert('submit!');
            this.$router.push({path:'/index'})
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
    }
};
</script>
<style lang="scss" scoped>
.login {
  width: 100%;
  height: 100%;
  background: url('../../assets/img/login-bg.jpg') no-repeat center center;
  background-size: 100% 100%;
  display: flex;
  flex-flow: row wrap;
  justify-content: center;
  align-items: center;
  .loginBox {
    width: 350px;
    height: 380px;
    padding: 20px;
    display: flex;
    flex-flow: column wrap;
    align-items: center;
    background: #fff;
    border-radius: 5px;
    .title {
      font-size: 20px;
      color: #333;
      padding: 15px 0 30px;
    }
    .demo-ruleForm{
        width:100%;
        .el-form-item{
            .el-input{
                width:100%;
            }
            .captcha-input{
                width:65%;
                margin-right:10px;
            }
        }
    }
    .loginBtn{
        width:100%;
        margin-top: 40px;
    }
    
  }
}
</style>